import matplotlib
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
matplotlib.use('TkAgg')
# 读取CSV数据
vertices = pd.read_csv("part2.csv")
edges = pd.read_csv("part1.csv")
# 创建NetworkX图
# G = nx.DiGraph()
# 添加节点
# for _, row in vertices.iterrows():
      G.add_node(row['id'], name=row['name'])
# 添加边
for _, row in edges.iterrows():
    G.add_edge(row['src'], row['dst'], label=row['relationship'])
# 可视化设置
plt.figure(figsize=(12, 8))
pos = nx.spring_layout(G)
labels = {node: data['name'] for node, data in G.nodes(data=True)}
edge_labels = {(u, v): d['label'] for u, v, d in G.edges(data=True)}
# 绘制图形
nx.draw_networkx_nodes(G, pos, node_size=2000, node_color='lightblue')
nx.draw_networkx_edges(G, pos, arrowstyle='->', arrowsize=20)
nx.draw_networkx_labels(G, pos, labels=labels, font_size=12)
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
plt.title("Social Network Analysis")
plt.axis('off')
plt.show()